home *** CD-ROM | disk | FTP | other *** search
/ Belgian Amiga Club - ADF Collection / BS1 part 60.zip / BS1 part 60 / Prof. Calc d1.adf / Rexx / SetEntryRange.rexx < prev    next >
OS/2 REXX Batch file  |  1993-03-17  |  2KB  |  121 lines

  1. /*
  2.     SetsEntryRange.rexx
  3. */
  4. options results
  5. address PCALC
  6.  
  7. 'current'
  8. range = result
  9.  
  10. colon = pos(':', range)
  11.  
  12. if colon = 0 then
  13. do
  14.     'DrawMessage' "Please select a range before executing this script"
  15.     exit
  16. end
  17.  
  18. 'GetString' "Proceed Horizontally or vertically? H/V"
  19. if upper(result) = V then 
  20.     direction = V
  21. else
  22.     direction = H
  23.  
  24. start_cell = substr(range, 1, colon - 1 )
  25. end_cell   = substr(range, colon + 1 )
  26.  
  27. start_row = cellrow(start_cell)
  28. end_row   = cellrow(end_cell)
  29. start_col = cellcol(start_cell)
  30. end_col   = cellcol(end_cell)
  31.  
  32. if direction = H then
  33. do row = start_row to end_row
  34.    do col = start_col to end_col
  35.       'position' makecell(row, col)
  36.       'GetString' "Entry Data and Press Return"
  37.       data = result
  38.  
  39.       if data = 'RESULT' then exit
  40.       if data ~= "" then
  41.          'PutCell' data
  42.    end
  43. end
  44. else
  45. do col = start_col to col
  46.    do row = start_row to end_row
  47.       'position' makecell(row, col)
  48.       'GetString' "Entry Data and Press Return"
  49.       data = result
  50.  
  51.       if data = 'RESULT' then exit
  52.       if data ~= "" then
  53.          'PutCell' data
  54.    end
  55. end
  56.  
  57. exit
  58.  
  59. cellrow: procedure
  60. do
  61.     parse arg cell
  62.  
  63.     do charpos = 2 to length(cell)
  64.         if datatype( substr(cell, charpos, 1), n ) then
  65.             return substr(cell, charpos)
  66.     end
  67.  
  68.     return 0
  69. end
  70.  
  71.  
  72.  
  73. cellcol: procedure
  74. do
  75.     parse arg cell
  76.  
  77.     labels = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
  78.     cell   = upper(cell)
  79.     len    = length(cell)
  80.  
  81.     val = 0
  82.  
  83.     do charpos = 1 to len
  84.         if datatype( substr(cell, charpos, 1), n ) then
  85.         do
  86.             cell = reverse(substr(cell, 1, charpos - 1))
  87.  
  88.             do x = 1 to length(cell)
  89.                 val = (26 ** (x - 1)) * pos(substr(cell, x, 1), labels) + val
  90.             end
  91.  
  92.            return val
  93.         end
  94.     end
  95.     return 0
  96.  
  97. end
  98.  
  99.  
  100. makecell: procedure
  101. do
  102.     parse arg row, col
  103.  
  104.     label = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
  105.  
  106.     /* no extensive mathematical functions built into arexx, so lets just
  107.      * calculate the column in a loop
  108.      */
  109.  
  110.     column = ""
  111.  
  112.     do while col > 0
  113.         mod = col // 26
  114.         col = col % 26
  115.         column = column || substr(label, mod, 1)
  116.     end
  117.  
  118.     return reverse(column) || row
  119. end
  120.  
  121.